package test.y2021;

import cn.hutool.core.lang.Console;
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.Security;
import java.security.spec.AlgorithmParameterSpec;

/**
 * Created By  醉美柳舞之众星捧月
 *
 * @author song
 * @date 2021/2/2 13:54
 */
public class January2 {

    private static final String sessionKey = "JKFfmfuvUxgX7alh4gfEtg==";
    private static final String data = "6AtCk436JgU4rSBL4CT7lcj+fKi+sEq0wGzy0e/H+s1PKWiIRf4gwrSRxdMmEI4K95z6k6qTzV/PBDXBjzH3j3RmLjiRJc3vaqhBB2cXSsWQjhrdxygDvta/y7/iaQTAIwBOg0tWdly+dyAK8vHdnw3+A6XK6+rq47oaFgcSass050jD8M144DRz6Wrya0NsRO6DwZJyZCdCZ1PQ1+HHhOTH+5jUQjmC5CMlqyxFmr7/zLhK4eQnB9G470uqISJ7qZihygEJZghFENhlmsqyel9ZOXMlO4c0uzbG2/WPZXNg5UZRYgjrM5rCpC3+GzGaygLc/jSXIJ9oUyKOW5HXTB3QWOeBeYIpg59Q8IRXG3yKIkAIbgV68ZW1wPs2pb4FKRuvIAnm7z/sWKB8KcDuMFAsCsEpSryUX61ySMOr2FHSGuwiudWGdV8FI70E/ohg2gtBVrLagZ9lnDb1xejuYf/vgkk9fJo8lb1/18ArbhU=";
    private static final String iv = "ILAcTymD5KxSRKFtRQ4WXQ==";


    public static void main(String[] args) throws Exception {

        Security.addProvider(new BouncyCastleProvider());

        String decrypt = decrypt();
        Console.error(decrypt);
    }

    private static String decrypt() throws Exception {

        byte[] keyByte = Base64.decodeBase64(sessionKey);
        byte[] ivByte = Base64.decodeBase64(iv);
        byte[] dataByte = Base64.decodeBase64(data);

        AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivByte);
        byte[] data;
        try {
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
            SecretKeySpec keySpec = new SecretKeySpec(keyByte, "AES");
            cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
            data = cipher.doFinal(dataByte);
        } catch (Exception e) {
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
            SecretKeySpec keySpec = new SecretKeySpec(keyByte, "AES");
            cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
            data = cipher.doFinal(dataByte);
        }
        return new String(data, "UTF-8");
    }
}
